#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/11/6 19:23
# @Author  : 作者名:张铁君
# @Site    :
# @File    : chrome_driver_config.py
# @Project : h5_auto_test
# @Software: PyCharm

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager


class EdgeDriverConfig:
    def driver_config(self, root_path='./'):
        """
        浏览器驱动
        :return:
        """
        # 自动下载驱动
        # path = EdgeChromiumDriverManager().install()
        # s = Service(path)
        s = Service(root_path + 'configuration/msedgedriver.exe')
        options = webdriver.EdgeOptions()
        options.use_chromium = True
        # 屏蔽inforbar
        options.add_experimental_option('useAutomationExtension', False)
        options.add_experimental_option('excludeSwitches', ['enable-automation', 'enable-logging'])
        options.add_argument("window-position=0,0")
        # 去除"chrome正受到自动测试软件的控制"的提示
        options.add_experimental_option("excludeSwitches", ["enable-automation"])
        options.add_argument("start-maximized")
        # 解决selenium无法访问https的问题
        options.add_argument("--ignore-certificate-errors")
        # 允许忽略localhost上的TLS/SSL错误
        options.add_argument("--allow-insecure-localhost")
        # 设置为无痕模式
        options.add_argument("--incognito")
        # 解决卡顿
        options.add_argument("--disable-gpu")
        options.add_argument("--no-sandbox")
        options.add_argument("--disable-dev-shm-usage")
        options.add_argument('--disable-infobars')  # 不显示 chrome正受到自动测试软件的控制。

        ## 禁用弹出拦截
        options.add_argument("--disable-popup-blocking")

        # 禁用浏览器弹窗
        # prefs = {
        #     'profile.default_content_setting_values': {
        #         'notifications': 2
        #     }
        # }
        # options.add_experimental_option('prefs', prefs)

        # options.add_argument('--headless')
        # options.binary_location = r'C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe'
        driver = webdriver.Edge(service=s, options=options)
        # 删除所有cookies
        driver.delete_all_cookies()
        # 设置为全屏模式
        driver.maximize_window()
        return driver
